class Solution {
    public int lengthOfLastWord(String s) {
        int cmd = 0;
        int count = 0;
        int len = s.length() - 1;
        while(len >= 0) {
            if(s.charAt(len) != ' ') {
                cmd = len;
                while(len >= 0 && s.charAt(len) != ' ') {
                    count = len;
                    len--;
                }
                break;
            }
            len--;
        }
        return cmd - count + 1;
    }
    public String longestCommonPrefix1(String[] strs) {
        if (strs == null || strs.length == 0) {
            return "";
        }
        for(int i = 0; i < strs[0].length() ; i++) {
            char tmp = strs[0].charAt(i);
            for(int j = 0; j < strs.length ; j++) {
                if(i == strs[j].length()||tmp != strs[j].charAt(i)) {
                    return strs[0].substring(0,i);
                }
            }
        }
        return strs[0];
    }
    public String longestCommonPrefix(String[] strs) {
        if (strs == null || strs.length == 0) {
            return "";
        }
        String prefix = strs[0];
        int count = strs.length;
        for (int i = 1; i < count; i++) {
            prefix = longestCommonPrefix(prefix, strs[i]);
            if (prefix.length() == 0) {
                break;
            }
        }
        return prefix;
    }

    public String longestCommonPrefix(String str1, String str2) {
        int length = Math.min(str1.length(), str2.length());
        int index = 0;
        while (index < length && str1.charAt(index) == str2.charAt(index)) {
            index++;
        }
        return str1.substring(0, index);
    }
}
